package com.mycompany.myapp.repository;

import com.mycompany.myapp.domain.UserRole;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * Spring Data SQL repository for the UserRole entity.
 */
@Repository
public interface UserRoleRepository extends JpaRepository<UserRole, Long> {
    @Query(
        value = "select distinct userRole from UserRole userRole left join fetch userRole.teachers left join fetch userRole.students",
        countQuery = "select count(distinct userRole) from UserRole userRole"
    )
    Page<UserRole> findAllWithEagerRelationships(Pageable pageable);

    @Query("select distinct userRole from UserRole userRole left join fetch userRole.teachers left join fetch userRole.students")
    List<UserRole> findAllWithEagerRelationships();

    @Query(
        "select userRole from UserRole userRole left join fetch userRole.teachers left join fetch userRole.students where userRole.id =:id"
    )
    Optional<UserRole> findOneWithEagerRelationships(@Param("id") Long id);
}
